//
//  DetailViewModel.m
//  HQJFacilitator
//
//  Created by mymac on 16/9/29.
//  Copyright © 2016年 Fujian first time iot technology investment co., LTD. All rights reserved.
//

#import "DetailViewModel.h"
#import "DerailModel.h"

@implementation DetailViewModel
-(void)requstAppOrgTyp:(NSInteger)orgTyp pag:(NSInteger)page andShowView:(UIView *)view {
    NSString *orgStr ;
    
    switch (orgTyp) {
        case 0:
            orgStr = @"myTradeList";
            break;
        case 1:
            orgStr = @"bonusChangeList";
            break;
        case 2:
            orgStr = @"bonusTransferList";
            break;
        case 3:
            orgStr = @"bonusGiftList";
            break;
        case 4:
            orgStr = @"myApplication";
            break;
        default:
            break;
    }
    NSString *memberidStr = [FileEngine filePathNameReadName:@"memberid" andstye:fileLoginStyle];
    if (memberidStr) {
        NSString *urlStr = [NSString stringWithFormat:@"%@%@/memberid/%@/page/%ld",AppOrg_URL,orgStr,memberidStr,(long)page];
        
        [RequestEngine HQJFacilitatorRequestDetailsUrl:urlStr complete:^(NSDictionary *dic) {
            HQJLog(@"在明细的ViewMode里面请求的数据是:%@",dic);
            if ([dic[@"error"]integerValue] == 47030) {
                
                _requstBlock(@[]);
                [ManagerEngine homeSvpStr:@"暂无数据" andcenterView:view andStyle:promptViewFadeAway];
                
                
            } else{
                NSArray *resultMsg = dic[@"result"];
                NSMutableArray *modelArr = [NSMutableArray arrayWithCapacity:resultMsg.count];
                for (NSDictionary *result in resultMsg) {
                    DerailModel *model = [[DerailModel alloc]init];
                    model =  [DerailModel mj_objectWithKeyValues:result];
                    
                    
                    
                    
                    [modelArr addObject: model];
                }
                
                
                
                //                        HQJLog(@"在明细的ViewMode里面请求的数据是:%@",dic);
                
                
                _requstBlock(modelArr);
            }
           
        } andError:^(NSError *error) {
            
        } ShowHUD:YES];
    } else {
        HQJLog(@"你还没有登录哦")
        
    }
   
    
    
}
@end
